package com.lvyq.myplayer.adapter


import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import com.daimajia.slider.library.SliderLayout
import com.daimajia.slider.library.SliderTypes.BaseSliderView
import com.daimajia.slider.library.SliderTypes.TextSliderView
import com.lvyq.myplayer.R
import com.lvyq.myplayer.common.util.MockDataUtil
import com.lvyq.myplayer.model.index.IndexBannerBean
import com.lvyq.myplayer.model.index.IndexBannerBeans


/**
 * 文件描述：IndexAdapter 首页-banner
 * 作者：lvyq
 * 创建时间：2025-03-24
 * 修改时间：2025-03-24
 */
class IndexBannerAdapter(var context: Context?): RecyclerView.Adapter<RecyclerView.ViewHolder>() {

    var bannerDatas:IndexBannerBean= MockDataUtil.getIndexBannerList()



    fun setData(bannerData:IndexBannerBean){
        this.bannerDatas=bannerData
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
                    val view = View.inflate(context, R.layout.item_index_top,null)
                    return indexBannerHolder(view)
    }

    override fun getItemCount(): Int {
            return  1
    }

    override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
        (holder as indexBannerHolder).setData(bannerDatas.rows)

    }

    /**
     * banner信息
     */

    inner  class  indexBannerHolder(item:View): RecyclerView.ViewHolder(item),
        BaseSliderView.OnSliderClickListener {
          val sliderLayout:SliderLayout
        init {
            sliderLayout = item.findViewById(R.id.slider);
        }
        fun setData(data: List<IndexBannerBeans>) {
            val url_maps = HashMap<String, String>()
            for (da in data){
                url_maps.put(da.id.toString(),da.bgImg)
            }
            if (url_maps.size>0){
                for ((key,value ) in url_maps){
                    val textSliderView = TextSliderView(context)
                    textSliderView
                        .description("") //显示文本
                        .image(value)
                        .setScaleType(BaseSliderView.ScaleType.Fit)
                        .setOnSliderClickListener(this)
                    sliderLayout.addSlider<BaseSliderView>(textSliderView)
                }
            }

        }

        override fun onSliderClick(slider: BaseSliderView?) {
            println("点击事件>>>"+slider?.url)
        }
    }

}